/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.lorentzos.flingswipe;

import ohos.app.Context;

/**
 * 尺寸工具类
 */
public class ScreenUtils {

    /**
     * 获取屏幕的高度Px
     *
     * @param context 上下文
     * @return 屏幕高度Px
     */
    public static final int getHeightInPx(Context context) {
        return context.getResourceManager().getDeviceCapability().height * context.getResourceManager().getDeviceCapability().screenDensity / 160;
    }

    /**
     * 获取屏幕的宽度Px
     *
     * @param context 上下文
     * @return 屏幕宽度Px
     */
    public static final int getWidthInPx(Context context) {
        return context.getResourceManager().getDeviceCapability().width * context.getResourceManager().getDeviceCapability().screenDensity / 160;
    }

    /**
     * 获取屏幕的高度Dp
     *
     * @param context 上下文
     * @return 屏幕高度dp
     */
    public static final int getHeightInDp(Context context) {
        return context.getResourceManager().getDeviceCapability().height;
    }

    /**
     * 获取屏幕的宽度Dp
     *
     * @param context Context
     * @return 屏幕宽度dp
     */
    public static final int getWidthInDp(Context context) {
        return context.getResourceManager().getDeviceCapability().width;
    }

    /**
     * dp转换为px
     *
     * @param context 上下文
     * @param vpValue dp
     * @return px
     */
    public static int vp2px(Context context, float vpValue) {
        return (int) (context.getResourceManager().getDeviceCapability().screenDensity / 160 * vpValue);
    }

    /**
     * px转换为dp
     *
     * @param context 上下文
     * @param pxValue px
     * @return dp
     */
    public static int px2vp(Context context, float pxValue) {
        return (int) (pxValue / (context.getResourceManager().getDeviceCapability().screenDensity / 160));
    }

}
